import 'package:flutter/material.dart';

class ProfilePage extends StatefulWidget {
  const ProfilePage({super.key, required this.userInfo});
  final Map userInfo;

  @override
  State<ProfilePage> createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  _showSheet() {
    // 底部半模态弹窗
    showModalBottomSheet(
      context: context,
      backgroundColor: Colors.white,
      builder: (context) {
        return SizedBox(
          height: 150,
          child: Column(
            children: [
              ListTile(
                leading: const Icon(Icons.camera_alt),
                title: const Text('拍照'),
                onTap: () {},
              ),
              ListTile(
                leading: const Icon(Icons.photo),
                title: const Text('相册'),
                onTap: () {},
              )
            ],
          ),
        );
      },
    );
  }

  //昵称控制器
  final _nicknameController = TextEditingController();
  @override
  void initState() {
    super.initState();
    _nicknameController.text = widget.userInfo['nickName']??'';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: const Text('个人信息'),
        backgroundColor: Colors.transparent,
        centerTitle: true,
      ),
      body: ListView(
        padding: const EdgeInsets.all(10),
        children: [
          SizedBox(
            height: 40,
            child: Row(
              children: [
                const Text(
                  '头像',
                  style: TextStyle(fontSize: 16),
                ),
                const Spacer(),
                GestureDetector(
                  onTap: () {
                    _showSheet();
                  },
                  child: Row(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(50.0),
                        child: widget.userInfo['avatar'] == null
                            ? Image.asset(
                                'assets/images/avatar_1.jpg',
                                width: 30,
                                height: 30,
                              )
                            : Image.network(
                                widget.userInfo['avatar'],
                                width: 30,
                                height: 30,
                              ),
                      ),
                      const Icon(Icons.arrow_forward_ios, size: 12)
                    ],
                  ),
                )
              ],
            ),
          ),
          Row(
            children: [
              const Text('昵称'),
              const Spacer(),
              Expanded(
                child: TextField(
                  controller: _nicknameController,
                  decoration: const InputDecoration(
                    hintText: '请输入昵称',
                    border: InputBorder.none,
                  ),
                  textAlign: TextAlign.right,
                ),
              ),
             const Icon(Icons.arrow_forward_ios, size: 12)
            ],
          )
        ],
      ),
    );
  }
}
